home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-ALPH.{_4 / IO.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  10KB  |  362 lines

  1. #ifndef __ALPHA_IO_H
  2. #define __ALPHA_IO_H
  3.  
  4. #include <linux/config.h>
  5. #include <asm/system.h>
  6.  
  7. /* We don't use IO slowdowns on the Alpha, but.. */
  8. #define __SLOW_DOWN_IO    do { } while (0)
  9. #define SLOW_DOWN_IO    do { } while (0)
  10.  
  11. /*
  12.  * Virtual -> physical identity mapping starts at this offset
  13.  */
  14. #ifdef USE_48_BIT_KSEG
  15. #define IDENT_ADDR     0xffff800000000000
  16. #else
  17. #define IDENT_ADDR     0xfffffc0000000000
  18. #endif
  19.  
  20. #ifdef __KERNEL__
  21. #include <asm/machvec.h>
  22.  
  23. /*
  24.  * We try to avoid hae updates (thus the cache), but when we
  25.  * do need to update the hae, we need to do it atomically, so
  26.  * that any interrupts wouldn't get confused with the hae
  27.  * register not being up-to-date with respect to the hardware
  28.  * value.
  29.  */
  30. static inline void __set_hae(unsigned long new_hae)
  31. {
  32.     unsigned long ipl = swpipl(7);
  33.  
  34.     alpha_mv.hae_cache = new_hae;
  35.     *alpha_mv.hae_register = new_hae;
  36.     mb();
  37.  
  38.     /* Re-read to make sure it was written.  */
  39.     new_hae = *alpha_mv.hae_register;
  40.     setipl(ipl);
  41. }
  42.  
  43. static inline void set_hae(unsigned long new_hae)
  44. {
  45.     if (new_hae != alpha_mv.hae_cache)
  46.         __set_hae(new_hae);
  47. }
  48.  
  49. /*
  50.  * Change virtual addresses to physical addresses and vv.
  51.  */
  52. static inline unsigned long virt_to_phys(volatile void * address)
  53. {
  54.     /* Conditionalize this on the CPU?  This here is 40 bits,
  55.        whereas EV4 only supports 34.  But KSEG is farther out
  56.        so it shouldn't _really_ matter.  */
  57.     return 0xffffffffffUL & (unsigned long) address;
  58. }
  59.  
  60. static inline void * phys_to_virt(unsigned long address)
  61. {
  62.     return (void *) (address + IDENT_ADDR);
  63. }
  64.  
  65. #else /* !__KERNEL__ */
  66.  
  67. /*
  68.  * Define actual functions in private name-space so it's easier to
  69.  * accommodate things like XFree or svgalib that like to define their
  70.  * own versions of inb etc.
  71.  */
  72. extern void __sethae (unsigned long addr);    /* syscall */
  73. extern void _sethae (unsigned long addr);    /* cached version */
  74.  
  75. #endif /* !__KERNEL__ */
  76.  
  77. /*
  78.  * There are different chipsets to interface the Alpha CPUs to the world.
  79.  */
  80.  
  81. #ifdef __KERNEL__
  82. #ifdef CONFIG_ALPHA_GENERIC
  83.  
  84. /* In a generic kernel, we always go through the machine vector.  */
  85.  
  86. # define virt_to_bus(a)    alpha_mv.mv_virt_to_bus(a)
  87. # define bus_to_virt(a)    alpha_mv.mv_bus_to_virt(a)
  88.  
  89. # define __inb        alpha_mv.mv_inb
  90. # define __inw        alpha_mv.mv_inw
  91. # define __inl        alpha_mv.mv_inl
  92. # define __outb        alpha_mv.mv_outb
  93. # define __outw        alpha_mv.mv_outw
  94. # define __outl        alpha_mv.mv_outl
  95.  
  96. # define __readb(a)    alpha_mv.mv_readb((unsigned long)(a))
  97. # define __readw(a)    alpha_mv.mv_readw((unsigned long)(a))
  98. # define __readl(a)    alpha_mv.mv_readl((unsigned long)(a))
  99. # define __readq(a)    alpha_mv.mv_readq((unsigned long)(a))
  100. # define __writeb(v,a)    alpha_mv.mv_writeb((v),(unsigned long)(a))
  101. # define __writew(v,a)    alpha_mv.mv_writew((v),(unsigned long)(a))
  102. # define __writel(v,a)    alpha_mv.mv_writel((v),(unsigned long)(a))
  103. # define __writeq(v,a)    alpha_mv.mv_writeq((v),(unsigned long)(a))
  104.  
  105. # define inb        __inb
  106. # define inw        __inw
  107. # define inl        __inl
  108. # define outb        __outb
  109. # define outw        __outw
  110. # define outl        __outl
  111.  
  112. # define readb        __readb
  113. # define readw        __readw
  114. # define readl        __readl
  115. # define readq        __readq
  116. # define writeb        __writeb
  117. # define writew        __writew
  118. # define writel        __writel
  119. # define writeq        __writeq
  120.  
  121. # define dense_mem(a)    alpha_mv.mv_dense_mem(a)
  122.  
  123. #else
  124.  
  125. /* Control how and what gets defined within the core logic headers.  */
  126. #define __WANT_IO_DEF
  127.  
  128. #if defined(CONFIG_ALPHA_APECS)
  129. # include <asm/core_apecs.h>
  130. #elif defined(CONFIG_ALPHA_CIA)
  131. # include <asm/core_cia.h>
  132. #elif defined(CONFIG_ALPHA_LCA)
  133. # include <asm/core_lca.h>
  134. #elif defined(CONFIG_ALPHA_MCPCIA)
  135. # include <asm/core_mcpcia.h>
  136. #elif defined(CONFIG_ALPHA_PYXIS)
  137. # include <asm/core_pyxis.h>
  138. #elif defined(CONFIG_ALPHA_T2)
  139. # include <asm/core_t2.h>
  140. #elif defined(CONFIG_ALPHA_TSUNAMI)
  141. # include <asm/core_tsunami.h>
  142. #elif defined(CONFIG_ALPHA_JENSEN)
  143. # include <asm/jensen.h>
  144. #elif defined(CONFIG_ALPHA_RX164)
  145. # include <asm/core_polaris.h>
  146. #else
  147. #error "What system is this?"
  148. #endif
  149.  
  150. #undef __WANT_IO_DEF
  151.  
  152. #endif /* GENERIC */
  153. #endif /* __KERNEL__ */
  154.  
  155. /*
  156.  * The convention used for inb/outb etc. is that names starting with
  157.  * two underscores are the inline versions, names starting with a
  158.  * single underscore are proper functions, and names starting with a
  159.  * letter are macros that map in some way to inline or proper function
  160.  * versions.  Not all that pretty, but before you change it, be sure
  161.  * to convince yourself that it won't break anything (in particular
  162.  * module support).
  163.  */
  164. extern unsigned int    _inb (unsigned long port);
  165. extern unsigned int    _inw (unsigned long port);
  166. extern unsigned int    _inl (unsigned long port);
  167. extern void        _outb (unsigned char b,unsigned long port);
  168. extern void        _outw (unsigned short w,unsigned long port);
  169. extern void        _outl (unsigned int l,unsigned long port);
  170. extern unsigned long    _readb(unsigned long addr);
  171. extern unsigned long    _readw(unsigned long addr);
  172. extern unsigned long    _readl(unsigned long addr);
  173. extern unsigned long    _readq(unsigned long addr);
  174. extern void        _writeb(unsigned char b, unsigned long addr);
  175. extern void        _writew(unsigned short b, unsigned long addr);
  176. extern void        _writel(unsigned int b, unsigned long addr);
  177. extern void        _writeq(unsigned long b, unsigned long addr);
  178.  
  179. #ifdef __KERNEL__
  180. /*
  181.  * The platform header files may define some of these macros to use
  182.  * the inlined versions where appropriate.  These macros may also be
  183.  * redefined by userlevel programs.
  184.  */
  185. #ifndef inb
  186. # define inb(p)        _inb((p))
  187. #endif
  188. #ifndef inw
  189. # define inw(p)        _inw((p))
  190. #endif
  191. #ifndef inl
  192. # define inl(p)        _inl((p))
  193. #endif
  194. #ifndef outb
  195. # define outb(b,p)    _outb((b),(p))
  196. #endif
  197. #ifndef outw
  198. # define outw(w,p)    _outw((w),(p))
  199. #endif
  200. #ifndef outl
  201. # define outl(l,p)    _outl((l),(p))
  202. #endif
  203.  
  204. #ifndef inb_p
  205. # define inb_p        inb
  206. #endif
  207. #ifndef inw_p
  208. # define inw_p        inw
  209. #endif
  210. #ifndef inl_p
  211. # define inl_p        inl
  212. #endif
  213.  
  214. #ifndef outb_p
  215. # define outb_p        outb
  216. #endif
  217. #ifndef outw_p
  218. # define outw_p        outw
  219. #endif
  220. #ifndef outl_p
  221. # define outl_p        outl
  222. #endif
  223.  
  224. #else 
  225.  
  226. /* Userspace declarations.  */
  227.  
  228. extern unsigned int    inb (unsigned long port);
  229. extern unsigned int    inw (unsigned long port);
  230. extern unsigned int    inl (unsigned long port);
  231. extern void        outb (unsigned char b,unsigned long port);
  232. extern void        outw (unsigned short w,unsigned long port);
  233. extern void        outl (unsigned int l,unsigned long port);
  234. extern unsigned long    readb(unsigned long addr);
  235. extern unsigned long    readw(unsigned long addr);
  236. extern unsigned long    readl(unsigned long addr);
  237. extern void        writeb(unsigned char b, unsigned long addr);
  238. extern void        writew(unsigned short b, unsigned long addr);
  239. extern void        writel(unsigned int b, unsigned long addr);
  240.  
  241. #endif /* __KERNEL__ */
  242.  
  243. #ifdef __KERNEL__
  244.  
  245. /*
  246.  * The "address" in IO memory space is not clearly either an integer or a
  247.  * pointer. We will accept both, thus the casts.
  248.  *
  249.  * On the alpha, we have the whole physical address space mapped at all
  250.  * times, so "ioremap()" and "iounmap()" do not need to do anything.
  251.  */
  252. static inline void * ioremap(unsigned long offset, unsigned long size)
  253. {
  254.     return (void *) offset;
  255.  
  256. static inline void iounmap(void *addr)
  257. {
  258. }
  259.  
  260. #ifndef readb
  261. # define readb(a)    _readb((unsigned long)(a))
  262. #endif
  263. #ifndef readw
  264. # define readw(a)    _readw((unsigned long)(a))
  265. #endif
  266. #ifndef readl
  267. # define readl(a)    _readl((unsigned long)(a))
  268. #endif
  269. #ifndef readq
  270. # define readq(a)    _readq((unsigned long)(a))
  271. #endif
  272. #ifndef writeb
  273. # define writeb(v,a)    _writeb((v),(unsigned long)(a))
  274. #endif
  275. #ifndef writew
  276. # define writew(v,a)    _writew((v),(unsigned long)(a))
  277. #endif
  278. #ifndef writel
  279. # define writel(v,a)    _writel((v),(unsigned long)(a))
  280. #endif
  281. #ifndef writeq
  282. # define writeq(v,a)    _writeq((v),(unsigned long)(a))
  283. #endif
  284.  
  285. /*
  286.  * String version of IO memory access ops:
  287.  */
  288. extern void _memcpy_fromio(void *, unsigned long, long);
  289. extern void _memcpy_toio(unsigned long, const void *, long);
  290. extern void _memset_c_io(unsigned long, unsigned long, long);
  291.  
  292. #define memcpy_fromio(to,from,len) \
  293.   _memcpy_fromio((to),(unsigned long)(from),(len))
  294. #define memcpy_toio(to,from,len) \
  295.   _memcpy_toio((unsigned long)(to),(from),(len))
  296. #define memset_io(addr,c,len) \
  297.   _memset_c_io((unsigned long)(addr),0x0101010101010101UL*(u8)(c),(len))
  298.  
  299. #define __HAVE_ARCH_MEMSETW_IO
  300. #define memsetw_io(addr,c,len) \
  301.   _memset_c_io((unsigned long)(addr),0x0001000100010001UL*(u16)(c),(len))
  302.  
  303. /*
  304.  * String versions of in/out ops:
  305.  */
  306. extern void insb (unsigned long port, void *dst, unsigned long count);
  307. extern void insw (unsigned long port, void *dst, unsigned long count);
  308. extern void insl (unsigned long port, void *dst, unsigned long count);
  309. extern void outsb (unsigned long port, const void *src, unsigned long count);
  310. extern void outsw (unsigned long port, const void *src, unsigned long count);
  311. extern void outsl (unsigned long port, const void *src, unsigned long count);
  312.  
  313. /*
  314.  * XXX - We don't have csum_partial_copy_fromio() yet, so we cheat here and 
  315.  * just copy it. The net code will then do the checksum later. Presently 
  316.  * only used by some shared memory 8390 Ethernet cards anyway.
  317.  */
  318.  
  319. #define eth_io_copy_and_sum(skb,src,len,unused) \
  320.   memcpy_fromio((skb)->data,(src),(len))
  321.  
  322. static inline int
  323. check_signature(unsigned long io_addr, const unsigned char *signature,
  324.         int length)
  325. {
  326.     int retval = 0;
  327.     do {
  328.         if (readb(io_addr) != *signature)
  329.             goto out;
  330.         io_addr++;
  331.         signature++;
  332.         length--;
  333.     } while (length);
  334.     retval = 1;
  335. out:
  336.     return retval;
  337. }
  338.  
  339. /*
  340.  * The Alpha Jensen hardware for some rather strange reason puts
  341.  * the RTC clock at 0x170 instead of 0x70. Probably due to some
  342.  * misguided idea about using 0x70 for NMI stuff.
  343.  *
  344.  * These defines will override the defaults when doing RTC queries
  345.  */
  346.  
  347. #ifdef CONFIG_ALPHA_GENERIC
  348. # define RTC_PORT(x)    ((x) + alpha_mv.rtc_port)
  349. #else
  350. # ifdef CONFIG_ALPHA_JENSEN
  351. #  define RTC_PORT(x)    (0x170+(x))
  352. # else
  353. #  define RTC_PORT(x)    (0x70 + (x))
  354. # endif
  355. #endif
  356. #define RTC_ALWAYS_BCD    0
  357.  
  358. #endif /* __KERNEL__ */
  359.  
  360. #endif /* __ALPHA_IO_H */
  361.